package com.chuanyang.driverh.mainhome;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseTitleActivity;
import com.chuanyang.driverh.responseresult.QualifyDetail;
import com.chuanyang.driverh.responseresult.QualifyDetailResult;
import com.chuanyang.driverh.utils.BitmapUtil;
import com.chuanyang.driverh.utils.ConstUtil;
import com.chuanyang.driverh.utils.DialogUtil;
import com.chuanyang.driverh.utils.PrintUtil;
import com.chuanyang.driverh.utils.net.JsonGenericsSerializator;
import com.chuanyang.driverh.utils.net.MyCallback;
import com.chuanyang.driverh.utils.net.MyHttpUtil;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;


public class ChosedQualifyActivity extends BaseTitleActivity {

    private ImageView iv_oldqualify_icon;
    private TextView tv_oldqualify_name;
    private TextView tv_oldqualify_phone;
    private TextView tv_oldqualify_tradetype;
    private TextView tv_oldqualify_startcity;
    private TextView tv_oldqualify_endcity;
    private TextView tv_oldqualify_waybillno;
    private TextView tv_oldqualify_time1;
    private TextView tv_oldqualify_goodname1;
    private TextView tv_oldqualify_goodweight1;
   // private TextView tv_oldqualify_goodprice1;
    private TextView tv_oldqualify_time2;
    private TextView tv_oldqualify_goodname2;
    private TextView tv_oldqualify_goodweight2;
    private TextView tv_oldqualify_goodprice2;
    private String advancedDriverId;
    private int type;
    private TextView tv_oldqualify_mark;

    @Override
    protected int getContentResId() {
        return R.layout.home_act_oldqualify;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        showActivityLoading();
        advancedDriverId = getIntent().getStringExtra("advancedDriverId");
        type = getIntent().getIntExtra("type",3);
        setBackImg();
        setTitle();
        findView();
        getData(advancedDriverId);
    }

    @Override
    public void initData() {

    }

    @Override
    protected void initListener() {

    }

    private void setTitle() {
        if(type==1)  {
            getTitleTextView().setText("已竞标单");
        }  else {
            getTitleTextView().setText("被选标单");
        }
        if(type==2)    {
            getRightTextView().setText("修改标单");
        }
    }
    private void fillView(QualifyDetail data)
    {
        BitmapUtil.showImgForNetPath( data.getUserImage(),iv_oldqualify_icon);
        tv_oldqualify_name.setText(data.getUsername());
        tv_oldqualify_phone.setText(data.getPhoneCall());
        if(data.getCurrency()==1)
        {
            tv_oldqualify_tradetype.setVisibility(View.GONE);
           // tv_oldqualify_goodprice1.setText(data.getPrice()+"￥/t");
            tv_oldqualify_goodprice2.setText(data.getDriverPrice()+"￥/t");

        }
        else {
           // tv_oldqualify_goodprice1.setText(data.getPrice()+"＄/t");
            tv_oldqualify_goodprice2.setText(data.getDriverPrice()+"＄/t");

        }
        if(TextUtils.isEmpty(data.getRemark()))
        {
            tv_oldqualify_mark.setText("---");
        }
        else {
            tv_oldqualify_mark.setText(data.getRemark());
        }
        tv_oldqualify_startcity.setText(data.getStartCity());
        tv_oldqualify_endcity.setText(data.getTargetCity());
        tv_oldqualify_goodname1.setText(data.getGoodsName());
        tv_oldqualify_goodweight1.setText(data.getGoodsWeight()+"t");
        tv_oldqualify_time1.setText(data.getOrder_endtime());
        tv_oldqualify_goodweight2.setText(data.getGoodsMaxWeight()+"t");
        tv_oldqualify_goodname2.setText(data.getGoodsName());
        tv_oldqualify_time2.setText(data.getBidTime());

    }
    private void findView() {
        iv_oldqualify_icon = (ImageView) findViewById(R.id.iv_oldqualify_icon);
        tv_oldqualify_name = (TextView) findViewById(R.id.tv_oldqualify_name);
        tv_oldqualify_phone = (TextView) findViewById(R.id.tv_oldqualify_phone);
        tv_oldqualify_tradetype = (TextView) findViewById(R.id.tv_oldqualify_tradetype);
        tv_oldqualify_startcity = (TextView) findViewById(R.id.tv_oldqualify_startcity);
        tv_oldqualify_endcity = (TextView) findViewById(R.id.tv_oldqualify_endcity);
        tv_oldqualify_waybillno = (TextView) findViewById(R.id.tv_oldqualify_waybillno);
        tv_oldqualify_time1 = (TextView) findViewById(R.id.tv_oldqualify_time1);
        tv_oldqualify_goodname1 = (TextView) findViewById(R.id.tv_oldqualify_goodname1);
        tv_oldqualify_goodweight1 = (TextView) findViewById(R.id.tv_oldqualify_goodweight1);
        //tv_oldqualify_goodprice1 = (TextView) findViewById(R.id.tv_oldqualify_goodprice1);
        tv_oldqualify_mark = (TextView) findViewById(R.id.tv_oldqualify_mark);
        tv_oldqualify_time2 = (TextView) findViewById(R.id.tv_oldqualify_time2);
        tv_oldqualify_goodname2 = (TextView) findViewById(R.id.tv_oldqualify_goodname2);
        tv_oldqualify_goodweight2 = (TextView) findViewById(R.id.tv_oldqualify_goodweight2);
        tv_oldqualify_goodprice2 = (TextView) findViewById(R.id.tv_oldqualify_goodprice2);

    }

    @Override
    protected void baseGoEnsure() {
        if(TextUtils.isEmpty(mBaseEnsure.getText()))
        {
            return;
        }
        else {
            Intent intent = new Intent(this, NewQualifyActivity.class);
            intent.putExtra("type", "2");
            intent.putExtra("advancedDriverId", advancedDriverId + "");
            startActivity(intent);
            finish();
        }
    }



    private void getData(String advancedDriverId ) {
        DialogUtil.showLoadingDialog(activityContext,"加载中...");
        Map<String,String> params=new HashMap<String, String>();
        params.put("advancedDriverId", advancedDriverId);
        MyHttpUtil.selectAdvancedDriverById(activityContext,params, new MyCallback<QualifyDetailResult>(activityContext,new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(activityContext, "网络异常，请稍后再试");
            }
            @Override
            public void onSuccess(QualifyDetailResult result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                        hideActivityLoading();
                        hideActivityLoading();
                        fillView(result.getData());
                }else{
                    PrintUtil.toast(activityContext,result.getMsg());
                }
            }
        });
    }


}
